import React, {PureComponent} from 'react';
import {connect} from 'dva';
import G from '../../utils/g';
import {
  Row,
  Col,
  Card,
  Form,
  Input,
  Select,
  Icon,
  Button,
  Dropdown,
  Menu,
  InputNumber,
  DatePicker,
  Modal,
  message,
  Badge,
  Divider,
  Checkbox,
  Popconfirm,
} from 'antd';

const FormItem = Form.Item;
const {Option} = Select;
const {RangePicker} = DatePicker;
const {TextArea} = Input;

@connect(({ goodsList, loading }) => ({
  goodsList,
  loading: loading.models.goodsList,
}))
@Form.create()
export default class SettingModal extends PureComponent {
  state = {
    modalVisible: true,
  };

  componentDidMount = ()=>{
    const { dispatch, type} = this.props;
    let payload = {
      status : 1,
      havSku : 1, //需要取出SKU
    };
    this.id = G.getUrlValue('id') || '';
    if(type == 'discount' && this.id){
      payload.promotionId = this.id;
    }
    dispatch({
      type: 'goodsList/fetch',
      payload,
    });
  };

  handleSubmit = e => {
    e.preventDefault();
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        this.props.dispatch({
          type: 'form/submitRegularForm',
          payload: values,
        });
      }
    });
  };

  handleModalVisible = flag => {
    this.props.handleHide(flag);
  };

  handleOk = ()=>{
    this.props.handleOk();
  }

  render() {
    const { rowSelection} = this.state;
    const {modalVisible, selectedRows} = this.props;
    const { goodsList: { data, group, category }, loading, type } = this.props;
    const {getFieldDecorator, getFieldValue } = this.props.form;

    console.log('selectedRows',selectedRows);

    const formItemLayout = {
      labelCol: {
        xs: {span: 24},
        sm: {span: 7},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 12},
        md: {span: 10},
      },
    };

    return (
      <Modal
        title={ '编辑邮箱'}
        width={300}
        visible={modalVisible}
        onOk={this.handleModalVisible}
        onCancel={()=>{this.handleModalVisible(false)}}
        footer={
          [
            <Button key="back" onClick={()=>{this.handleModalVisible(false)}}>取消</Button>,
            <Button key="submit" type="primary" onClick={this.handleOk}>
              确定
            </Button>,
          ]
        }
      >
        <Form onSubmit={this.handleSbumit} layout="inline" style={{marginBottom:'16px'}}>
          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
            <Col md={24} sm={24} style={{textAlign:'right'}}>
              <FormItem label="邮箱地址">
                {getFieldDecorator('email')(<Input placeholder="请输入" />)}
              </FormItem>
            </Col>
          </Row>
        </Form>
      </Modal>
    );
  }
}
